!(function (e) {
  var r,
    t = '[big.js] ',
    n = t + 'Invalid ',
    i = n + 'decimal places',
    o = {},
    s = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
  function f(e, r, t, n) {
    var i = e.c,
      o = e.e + r + 1;
    if (o < i.length) {
      if (1 === t) n = i[o] >= 5;
      else if (2 === t)
        n =
          i[o] > 5 ||
          (5 == i[o] && (n || o < 0 || void 0 !== i[o + 1] || 1 & i[o - 1]));
      else if (3 === t) n = n || !!i[0];
      else if (((n = !1), 0 !== t))
        throw Error('[big.js] Invalid rounding mode');
      if (o < 1)
        (i.length = 1), n ? ((e.e = -r), (i[0] = 1)) : (i[0] = e.e = 0);
      else {
        if (((i.length = o--), n))
          for (; ++i[o] > 9; ) (i[o] = 0), o-- || (++e.e, i.unshift(1));
        for (o = i.length; !i[--o]; ) i.pop();
      }
    } else if (t < 0 || t > 3 || t !== ~~t)
      throw Error('[big.js] Invalid rounding mode');
    return e;
  }
  function c(e, r, t, o) {
    var s,
      c,
      u = e.constructor,
      h = !e.c[0];
    if (void 0 !== t) {
      if (t !== ~~t || t < (3 == r) || t > 1e6)
        throw Error(3 == r ? n + 'precision' : i);
      for (
        t = o - (e = new u(e)).e,
          e.c.length > ++o && f(e, t, u.RM),
          2 == r && (o = e.e + t + 1);
        e.c.length < o;

      )
        e.c.push(0);
    }
    if (
      ((s = e.e),
      (t = (c = e.c.join('')).length),
      2 != r && (1 == r || (3 == r && o <= s) || s <= u.NE || s >= u.PE))
    )
      c =
        c.charAt(0) +
        (t > 1 ? '.' + c.slice(1) : '') +
        (s < 0 ? 'e' : 'e+') +
        s;
    else if (s < 0) {
      for (; ++s; ) c = '0' + c;
      c = '0.' + c;
    } else if (s > 0)
      if (++s > t) for (s -= t; s--; ) c += '0';
      else s < t && (c = c.slice(0, s) + '.' + c.slice(s));
    else t > 1 && (c = c.charAt(0) + '.' + c.slice(1));
    return e.s < 0 && (!h || 4 == r) ? '-' + c : c;
  }
  (o.abs = function () {
    var e = new this.constructor(this);
    return (e.s = 1), e;
  }),
    (o.cmp = function (e) {
      var r,
        t = this,
        n = t.c,
        i = (e = new t.constructor(e)).c,
        o = t.s,
        s = e.s,
        f = t.e,
        c = e.e;
      if (!n[0] || !i[0]) return n[0] ? o : i[0] ? -s : 0;
      if (o != s) return o;
      if (((r = o < 0), f != c)) return (f > c) ^ r ? 1 : -1;
      for (s = (f = n.length) < (c = i.length) ? f : c, o = -1; ++o < s; )
        if (n[o] != i[o]) return (n[o] > i[o]) ^ r ? 1 : -1;
      return f == c ? 0 : (f > c) ^ r ? 1 : -1;
    }),
    (o.div = function (e) {
      var r = this,
        t = r.constructor,
        n = r.c,
        o = (e = new t(e)).c,
        s = r.s == e.s ? 1 : -1,
        c = t.DP;
      if (c !== ~~c || c < 0 || c > 1e6) throw Error(i);
      if (!o[0]) throw Error('[big.js] Division by zero');
      if (!n[0]) return new t(0 * s);
      var u,
        h,
        l,
        a,
        d,
        g = o.slice(),
        v = (u = o.length),
        p = n.length,
        w = n.slice(0, u),
        m = w.length,
        E = e,
        b = (E.c = []),
        M = 0,
        P = c + (E.e = r.e - e.e) + 1;
      for (E.s = s, s = P < 0 ? 0 : P, g.unshift(0); m++ < u; ) w.push(0);
      do {
        for (l = 0; l < 10; l++) {
          if (u != (m = w.length)) a = u > m ? 1 : -1;
          else
            for (d = -1, a = 0; ++d < u; )
              if (o[d] != w[d]) {
                a = o[d] > w[d] ? 1 : -1;
                break;
              }
          if (!(a < 0)) break;
          for (h = m == u ? o : g; m; ) {
            if (w[--m] < h[m]) {
              for (d = m; d && !w[--d]; ) w[d] = 9;
              --w[d], (w[m] += 10);
            }
            w[m] -= h[m];
          }
          for (; !w[0]; ) w.shift();
        }
        (b[M++] = a ? l : ++l), w[0] && a ? (w[m] = n[v] || 0) : (w = [n[v]]);
      } while ((v++ < p || void 0 !== w[0]) && s--);
      return (
        b[0] || 1 == M || (b.shift(), E.e--),
        M > P && f(E, c, t.RM, void 0 !== w[0]),
        E
      );
    }),
    (o.eq = function (e) {
      return !this.cmp(e);
    }),
    (o.gt = function (e) {
      return this.cmp(e) > 0;
    }),
    (o.gte = function (e) {
      return this.cmp(e) > -1;
    }),
    (o.lt = function (e) {
      return this.cmp(e) < 0;
    }),
    (o.lte = function (e) {
      return this.cmp(e) < 1;
    }),
    (o.minus = o.sub =
      function (e) {
        var r,
          t,
          n,
          i,
          o = this,
          s = o.constructor,
          f = o.s,
          c = (e = new s(e)).s;
        if (f != c) return (e.s = -c), o.plus(e);
        var u = o.c.slice(),
          h = o.e,
          l = e.c,
          a = e.e;
        if (!u[0] || !l[0]) return l[0] ? ((e.s = -c), e) : new s(u[0] ? o : 0);
        if ((f = h - a)) {
          for (
            (i = f < 0) ? ((f = -f), (n = u)) : ((a = h), (n = l)),
              n.reverse(),
              c = f;
            c--;

          )
            n.push(0);
          n.reverse();
        } else
          for (
            t = ((i = u.length < l.length) ? u : l).length, f = c = 0;
            c < t;
            c++
          )
            if (u[c] != l[c]) {
              i = u[c] < l[c];
              break;
            }
        if (
          (i && ((n = u), (u = l), (l = n), (e.s = -e.s)),
          (c = (t = l.length) - (r = u.length)) > 0)
        )
          for (; c--; ) u[r++] = 0;
        for (c = r; t > f; ) {
          if (u[--t] < l[t]) {
            for (r = t; r && !u[--r]; ) u[r] = 9;
            --u[r], (u[t] += 10);
          }
          u[t] -= l[t];
        }
        for (; 0 === u[--c]; ) u.pop();
        for (; 0 === u[0]; ) u.shift(), --a;
        return u[0] || ((e.s = 1), (u = [(a = 0)])), (e.c = u), (e.e = a), e;
      }),
    (o.mod = function (e) {
      var r,
        t = this,
        n = t.constructor,
        i = t.s,
        o = (e = new n(e)).s;
      if (!e.c[0]) throw Error('[big.js] Division by zero');
      return (
        (t.s = e.s = 1),
        (r = 1 == e.cmp(t)),
        (t.s = i),
        (e.s = o),
        r
          ? new n(t)
          : ((i = n.DP),
            (o = n.RM),
            (n.DP = n.RM = 0),
            (t = t.div(e)),
            (n.DP = i),
            (n.RM = o),
            this.minus(t.times(e)))
      );
    }),
    (o.plus = o.add =
      function (e) {
        var r,
          t = this,
          n = t.constructor,
          i = t.s,
          o = (e = new n(e)).s;
        if (i != o) return (e.s = -o), t.minus(e);
        var s = t.e,
          f = t.c,
          c = e.e,
          u = e.c;
        if (!f[0] || !u[0]) return u[0] ? e : new n(f[0] ? t : 0 * i);
        if (((f = f.slice()), (i = s - c))) {
          for (
            i > 0 ? ((c = s), (r = u)) : ((i = -i), (r = f)), r.reverse();
            i--;

          )
            r.push(0);
          r.reverse();
        }
        for (
          f.length - u.length < 0 && ((r = u), (u = f), (f = r)),
            i = u.length,
            o = 0;
          i;
          f[i] %= 10
        )
          o = ((f[--i] = f[i] + u[i] + o) / 10) | 0;
        for (o && (f.unshift(o), ++c), i = f.length; 0 === f[--i]; ) f.pop();
        return (e.c = f), (e.e = c), e;
      }),
    (o.pow = function (e) {
      var r = this,
        t = new r.constructor(1),
        i = t,
        o = e < 0;
      if (e !== ~~e || e < -1e6 || e > 1e6) throw Error(n + 'exponent');
      for (o && (e = -e); 1 & e && (i = i.times(r)), (e >>= 1); )
        r = r.times(r);
      return o ? t.div(i) : i;
    }),
    (o.round = function (e, r) {
      var t = this.constructor;
      if (void 0 === e) e = 0;
      else if (e !== ~~e || e < -1e6 || e > 1e6) throw Error(i);
      return f(new t(this), e, void 0 === r ? t.RM : r);
    }),
    (o.sqrt = function () {
      var e,
        r,
        n,
        i = this,
        o = i.constructor,
        s = i.s,
        c = i.e,
        u = new o(0.5);
      if (!i.c[0]) return new o(i);
      if (s < 0) throw Error(t + 'No square root');
      0 === (s = Math.sqrt(i + '')) || s === 1 / 0
        ? (((r = i.c.join('')).length + c) & 1 || (r += '0'),
          (c = (((c + 1) / 2) | 0) - (c < 0 || 1 & c)),
          (e = new o(
            ((s = Math.sqrt(r)) == 1 / 0
              ? '1e'
              : (s = s.toExponential()).slice(0, s.indexOf('e') + 1)) + c,
          )))
        : (e = new o(s)),
        (c = e.e + (o.DP += 4));
      do {
        (n = e), (e = u.times(n.plus(i.div(n))));
      } while (n.c.slice(0, c).join('') !== e.c.slice(0, c).join(''));
      return f(e, (o.DP -= 4), o.RM);
    }),
    (o.times = o.mul =
      function (e) {
        var r,
          t = this,
          n = t.constructor,
          i = t.c,
          o = (e = new n(e)).c,
          s = i.length,
          f = o.length,
          c = t.e,
          u = e.e;
        if (((e.s = t.s == e.s ? 1 : -1), !i[0] || !o[0]))
          return new n(0 * e.s);
        for (
          e.e = c + u,
            s < f && ((r = i), (i = o), (o = r), (u = s), (s = f), (f = u)),
            r = new Array((u = s + f));
          u--;

        )
          r[u] = 0;
        for (c = f; c--; ) {
          for (f = 0, u = s + c; u > c; )
            (f = r[u] + o[c] * i[u - c - 1] + f),
              (r[u--] = f % 10),
              (f = (f / 10) | 0);
          r[u] = (r[u] + f) % 10;
        }
        for (f ? ++e.e : r.shift(), c = r.length; !r[--c]; ) r.pop();
        return (e.c = r), e;
      }),
    (o.toExponential = function (e) {
      return c(this, 1, e, e);
    }),
    (o.toFixed = function (e) {
      return c(this, 2, e, this.e + e);
    }),
    (o.toPrecision = function (e) {
      return c(this, 3, e, e - 1);
    }),
    (o.toString = function () {
      return c(this);
    }),
    (o.valueOf = o.toJSON =
      function () {
        return c(this, 4);
      }),
    ((r = (function e() {
      function r(t) {
        var i = this;
        if (!(i instanceof r)) return void 0 === t ? e() : new r(t);
        t instanceof r
          ? ((i.s = t.s), (i.e = t.e), (i.c = t.c.slice()))
          : (function (e, r) {
              var t, i, o;
              if (0 === r && 1 / r < 0) r = '-0';
              else if (!s.test((r += ''))) throw Error(n + 'number');
              (e.s = '-' == r.charAt(0) ? ((r = r.slice(1)), -1) : 1),
                (t = r.indexOf('.')) > -1 && (r = r.replace('.', ''));
              (i = r.search(/e/i)) > 0
                ? (t < 0 && (t = i),
                  (t += +r.slice(i + 1)),
                  (r = r.substring(0, i)))
                : t < 0 && (t = r.length);
              for (o = r.length, i = 0; i < o && '0' == r.charAt(i); ) ++i;
              if (i == o) e.c = [(e.e = 0)];
              else {
                for (; o > 0 && '0' == r.charAt(--o); );
                for (e.e = t - i - 1, e.c = [], t = 0; i <= o; )
                  e.c[t++] = +r.charAt(i++);
              }
            })(i, t),
          (i.constructor = r);
      }
      return (
        (r.prototype = o),
        (r.DP = 20),
        (r.RM = 1),
        (r.NE = -7),
        (r.PE = 21),
        (r.version = '5.2.2'),
        r
      );
    })()).default = r.Big =
      r),
    'function' == typeof define && define.amd
      ? define(function () {
          return r;
        })
      : 'undefined' != typeof module && module.exports
        ? (module.exports = r)
        : ((void 0).Big = r);
})();
